.\"     Title: IPSEC_OPTIONSFROM
.\"    Author: 
.\" Generator: DocBook XSL Stylesheets v1.73.2 <http://docbook.sf.net/>
.\"      Date: 11/14/2008
.\"    Manual: 16 Oct 1998
.\"    Source: 16 Oct 1998
.\"
.TH "IPSEC_OPTIONSFROM" "3" "11/14/2008" "16 Oct 1998" "16 Oct 1998"
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.SH "NAME"
ipsec_optionsfrom \- read additional ``command-line'' options from file
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <freeswan\.h>

.fi
.ft
.HP 24
.BI "const char *optionsfrom(char\ *\ " "filename" ", int\ *\ " "argcp" ", char\ ***\ " "argvp" ", int\ " "optind" ", FILE\ *\ " "errsto" ");"
.SH "DESCRIPTION"
.PP
\fIOptionsfrom\fR
is called from within a
\fBgetopt_long\fR(3)
scan, as the result of the appearance of an option (preferably
\fB\-\-optionsfrom\fR) to insert additional \(lqcommand\-line\(rq arguments into the scan immediately after the option\. Typically this would be done to pick up options which are security\-sensitive and should not be visible to
\fBps\fR(1)
and similar commands, and hence cannot be supplied as part of the actual command line or the environment\.
.PP
\fIOptionsfrom\fR
reads the additional arguments from the specified
\fIfilename\fR, allocates a new argument vector to hold pointers to the existing arguments plus the new ones, and amends
\fIargc\fR
and
\fIargv\fR
(via the pointers
\fIargcp\fR
and
\fIargvp\fR, which must point to the
\fIargc\fR
and
\fIargv\fR
being supplied to
\fBgetopt_long\fR(3)) accordingly\.
\fIOptind\fR
must be the index, in the original argument vector, of the next argument\.
.PP
If
\fIerrsto\fR
is NULL,
\fBoptionsfrom\fR
returns NULL for success and a pointer to a string\-literal error message for failure; see DIAGNOSTICS\. If
\fIerrsto\fR
is non\-NULL and an error occurs,
\fBoptionsfrom\fR
prints a suitable complaint onto the
\fIerrsto\fR
descriptor and invokes
\fIexit\fR
with an exit status of 2; this is a convenience for cases where more sophisticated responses are not required\.
.PP
The text of existing arguments is not disturbed by
\fBoptionsfrom\fR, so pointers to them and into them remain valid\.
.PP
The file of additional arguments is an ASCII text file\. Lines consisting solely of white space, and lines beginning with
\fB#\fR, are comments and are ignored\. Otherwise, a line which does not begin with
\fB\-\fR
is taken to be a single argument; if it both begins and ends with double\-quote ("), those quotes are stripped off (note, no other processing is done within the line!)\. A line beginning with
\fB\-\fR
is considered to contain multiple arguments separated by white space\.
.PP
Because
\fBoptionsfrom\fR
reads its entire file before the
\fBgetopt_long\fR(3)
scan is resumed, an
\fBoptionsfrom\fR
file can contain another
\fB\-\-optionsfrom\fR
option\. Obviously, infinite loops are possible here\. If
\fIerrsto\fR
is non\-NULL,
\fBoptionsfrom\fR
considers it an error to be called more than 100 times\. If
\fIerrsto\fR
is NULL, loop detection is up to the caller (and the internal loop counter is zeroed out)\.
.SH "EXAMPLE"
.PP
A reasonable way to invoke
\fBoptionsfrom\fR
would be like so:
.sp
.RS 4
.nf
#include <getopt\.h>

struct option opts[] = {
	/* \.\.\. */
	"optionsfrom",	1,	NULL,	\'+\',
	/* \.\.\. */
};

int
main(argc, argv)
int argc;
char *argv[];
{
	int opt;
	extern char *optarg;
	extern int optind;

	while ((opt = getopt_long(argc, argv, "", opts, NULL)) != EOF)
		switch (opt) {
		/* \.\.\. */
		case \'+\':	/* optionsfrom */
			optionsfrom(optarg, &argc, &argv, optind, stderr);
			/* does not return on error */
			break;
		/* \.\.\. */
		}
	/* \.\.\. */
.fi
.RE
.sp
.SH "SEE ALSO"
.PP
\fBgetopt_long\fR(3)
.SH "DIAGNOSTICS"
.PP
Errors in
\fBoptionsfrom\fR
are: unable to open file; attempt to allocate temporary storage for argument or argument vector failed; read error in file; line too long\.
.SH "HISTORY"
.PP
Written for the FreeS/WAN project by Henry Spencer\.
.SH "BUGS"
.PP
The double\-quote convention is rather simplistic\.
.PP
Line length is currently limited to 1023 bytes, and there is no continuation convention\.
.PP
The restriction of error reports to literal strings (so that callers don\'t need to worry about freeing them or copying them) does limit the precision of error reporting\.
.PP
The error\-reporting convention lends itself to slightly obscure code, because many readers will not think of NULL as signifying success\.
.PP
There is a certain element of unwarranted chumminess with the insides of
\fBgetopt_long\fR(3)
here\. No non\-public interfaces are actually used, but
\fBoptionsfrom\fR
does rely on
\fBgetopt_long\fR(3)
being well\-behaved in certain ways that are not actually promised by the specs\.
